<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta http-equiv="Content-Type" content="multipart/form-data; charset=utf-8" />
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" method="POST" id="form-huiyuan-add" enctype="multipart/form-data">
			<div class="form-group">	
				<label class="col-sm-3 control-label">上级会员ID：</label>
				<div class="col-sm-8">
					<input id="parentId" name="parentId" class="form-control" type="text">
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">会员名称：</label>
				<div class="col-sm-8">
					<input id="mingCheng" name="mingCheng" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">姓名：</label>
				<div class="col-sm-8">
					<input id="name" name="name" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">电话：</label>
				<div class="col-sm-8">
					<input id="telPhone" name="telPhone" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">密码：</label>
				<div class="col-sm-8">
					<input class="form-control" type="password" name="password" id="password" th:value="${@config.getKey('sys.user.initPassword')}">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">地址：</label>
				<div class="col-sm-8">
					<input id="adress" name="adress" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">单位：</label>
				<div class="col-sm-8">
					<input id="danWei" name="danWei" class="form-control" type="text">
				</div>
			</div>

			<div class="form-group">	
				<label class="col-sm-3 control-label">会员照片：</label>
				<div class="col-sm-8">
					<input type="file" name="files" onchange="addFile(this)" >
				</div>
			</div>

		</form>
	</div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		function addFile(obj) {
			var o = $(obj);
			var len = o.parent().find('input').length;
			if(o[0].value == ''){
				if(len > 1){
					o.remove();
				}
			}else{
				o.parent().append('<input type="file" name="files" onchange="addFile(this)">')
			}
		}
		var prefix = ctx + "system/huiyuan"
		$("#form-huiyuan-add").validate({
			rules:{
				xxxx:{
					required:true,
				},
			}
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	        	var ids = '';
	        	$(':file').each(function(i){
	        		if($(this).val() != ''){
						$(this).attr('id', 'img'+i)
						ids += ',img'+i;
					}
				});
	            $.operate.save2(prefix + "/add", $('#form-huiyuan-add').serialize(), ids.substring(1));
	        }
	    }
		$.fn.imgs = function(e) {
			var fileObj = $('<input type="file">');
			var name = "";
			if (this.attr('name')) {
				name = ' name="' + this.attr('name') + '"';
			}
			var hiddenObj = $('<input type="hidden"' + name + '">');
			this.parent().append(hiddenObj);
			var imgObj = $(this.attr('img'));
			fileObj.trigger('click');
			fileObj.change(function() {
				var reader = new FileReader();
				reader.onload = function(e) {
					imgObj.attr('src', e.target.result);
					hiddenObj.val(e.target.result)
				}
				reader.readAsDataURL($(this).context.files[0]);
			});
		}
	</script>

</body>
</html>
